﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace aboveXWords.GUI
{
  /// <summary>
  /// Picture - selfevident
  /// </summary>
  [Serializable]
  public class Picture : ResizableSquare
  {
    public Picture(float x, float y, float width, float height) : base(x, y, width, height)
    {
    }

    /// <summary>
    /// The image to draw.
    /// </summary>
    public Image Image { get; set; }
    public Sentense Sentense { get; set; }
    public string Value { get; set; }

    /// <summary>
    /// Draw the image and the surrounding square.
    /// </summary>
    /// <param name="graphics"></param>
    protected internal override void Paint(Graphics graphics)
    {
      base.Paint(graphics);
      GraphicsUnit units = GraphicsUnit.Pixel;
      if (Image != null)
        graphics.DrawImage(Image, Rectangle, Image.GetBounds(ref units), GraphicsUnit.Pixel);
      else
        graphics.FillRectangle(Painter.Colors.SentenseBrush, Rectangle);
    }

    /// <summary>
    /// Edit the picture, return true if we've changed the sentense.
    /// </summary>
    /// <param name="canvas"></param>
    /// <returns></returns>
    internal bool Edit(Canvas canvas)
    {
      string oldSentense = Value;
      PictureDialog pictureDialog = new PictureDialog(this);
      if (pictureDialog.ShowDialog() != DialogResult.OK) return false;
      Invalidate(canvas);
      return oldSentense != Value;
    }
  }
}